<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="version" content="Alidao v1.0 20151012">
    <meta http-equiv="Cache-Control" content="must-revalidate,no-cache">
    <meta http-equiv="x-dns-prefetch-control" content="on" />
    <title>老年人生活评定</title>
    <link type="text/css" rel="stylesheet" href="${ctx}/static/healthassess/css/common.css" />
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/list.css">
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/health.css">
</head>

<body>
<div class="container health">
    <input type="hidden" value="4" id="questionnaire_id" >

    <div class="question-list" id="question_list" style="display:none">
        <h4 class="ps">您是否能独自完成以下行为?</h4>
    </div>
    <footer class="footer btn-one" style="display:none">
        <a class="bder-radius-4" id="submit" href="javascript:void(0);" onclick="submit()">提交</a>
    </footer>
    <section class="result" id="result" style="display:none">${result}
        <footer class="footer btn-one">
            <a class="bder-radius-4 active"   href="javascript:void(0);" onclick="redo()">重新评估</a>
        </footer>
        <div style="position: fixed; right:1rem; top: 2rem;">
            <div style="width: 100%; text-align: center;">
                <a href="${ctx}/h5/health/assessment1?uid=${uid}">
                    <button type="button" data-loading-text="返回" class="mui-btn-circle"
                            onclick="">返回</button></a>
            </div>
        </div>
    </section>
</div>
<script src="${ctx}/static/healthassess/js/jquery-2.1.4.min.js"></script>
<script src="${ctx}/static/healthassess/js/jquery.mobile.custom.min.js"></script>
<script src="${ctx}/static/healthassess/js/common.js"></script>
<script>
    var questionJson = [{
        type: "radio",
        question: "使用公共汽车", //A为1分  B为2分 C为3分 D为4分 总计得分
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "行走",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ],
        },
    }, {
        type: "radio",
        question: "做饭菜",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "做家务",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "吃药",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "吃饭",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "穿衣",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "梳头、刷牙等",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "洗头",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "洗澡",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "购物",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "定时上厕所",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "打电话",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }, {
        type: "radio",
        question: "处理自己钱财",
        answer: {
            answerArray: [
                "完全可以", "有些困难 ", "需要帮助", "根本无法做",
            ]
        },
    }];
</script>
<script>
    $(function() {
        if (${not empty result}) {
            $("#result").show();
            return;
        }else{
            $("#result").siblings("div,footer").show();
        }
        select_click();
        verify();
    });
    var scoreArray = [];
    var select_click = function() {
        $(".list").each(function(index) {
            $(this).find("li").tap(function() {
                onSelecting($(this));
                getAnswer(index, $(this));
                var score = $(this).index() + 1;
                scoreArray[index] = score;
                verify();
            })
        })
    };
    var resultHtml;
    var sum = 0;

    function result_html(){
        resultHtml="";
        for (var i = 0; i < scoreArray.length; i++) {
            sum += scoreArray[i];
        };
        if (sum <= 16) {
            resultHtml = '<div class="result-list">' +
            '<h4 style="border-bottom:none;">生活功能完全正常</h4>' +
            '</div>';
        } else if (sum > 16 && sum < 22) {
            resultHtml = '<div class="result-list">' +
            '<h4 style="border-bottom:none;">生活功能有不同程度的功能下降，可进行康复训练。</h4>' +
            '</div>';
        } else if (sum >= 22) {
            resultHtml = '<div class="result-list">' +
            '<h4 style="border-bottom:none;">生活功能有明细障碍，需加强看护，以防意外事件发生。</h4>' +
            '</div>';
        };
    }

    function verify(){
        var questionLength=$(".question").length;
        var isDo=$("[data-status='do']");
        if(isDo.length<questionLength){
            $("#submit").removeClass('active').attr("onclick","");
        }else{
            $("#submit").addClass('active').attr("onclick","submit()");
        }
    }

    function submit() {
        result_html();
        getData();
        var result = resultHtml;
        var questionArray = dataArr;
        var questionnaire_id = "4";
        var questionnaire = "老年人生活评定";
        var data = {
            uid: ${uid},
            questionnaireId: questionnaire_id,
            questionnaire: questionnaire,
            questionArray: JSON.stringify(questionArray),
            result: result,
            score: sum
        };
        $.ajax({
            url: '${ctx}/h5/health/assessment/save',
            type: 'post',
            data: data,
            dataType: "jsonp",
            success:function(){

            },
            error:function(){

            }
        });
        $(window).scrollTop(0);
        $("#result footer").before(resultHtml);
        $("#result").siblings('div,footer').hide();
        $("#result").show();
        $("#tips").hide();
    }

</script>
</body>

</html>
